<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                xmlns:comp="http://java.sun.com/jsf/composite/comp"
                template="./template.xhtml">

    <ui:define name="content">

        <h:form id="form" >

            <p:messages id="messages" autoUpdate="true"/> 

            <p:panelGrid id="panelGrid" columns="2">
                <f:facet name="header">
                    <h:outputText value="Sharing: #{sharingManagedBean.path}"/>
                </f:facet>

                <p:panelGrid columns="2" styleClass="noBorders">

                    <h:outputLabel value="Sharing with *" for="shUserName" />
                    <p:inputText id="shUserName" value="#{sharingManagedBean.userName}" title="Sharing with" required="true" label="Sharing with" style="width: 180px"/>
                    <h:outputText value="Rights: " />  
                    <p:selectOneListbox id="rights" value="#{sharingManagedBean.rights}" style="width: 182px" label="Rights" required="true">  
                        <f:selectItem itemLabel="Read" itemValue="1" />  
                        <f:selectItem itemLabel="Write" itemValue="2" />  
                        <f:selectItem itemLabel="Delete" itemValue="3" />  
                    </p:selectOneListbox>                    

                </p:panelGrid>


                <p:outputPanel id="sharingUsers" >
                    <p:dataTable var="user" value="#{sharingManagedBean.datas}" style="width: 700px">
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="User name" />  
                            </f:facet>  
                            <h:outputText value="#{user.user.name}" />  
                        </p:column>  

                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Rights" />  
                            </f:facet>  
                            <h:outputText  value="#{user.rights.type}"/>  
                        </p:column>  

                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Assigned" />  
                            </f:facet>  
                            <h:outputText value="#{user.assigned}"/>
                        </p:column>
                        <p:column>
                            <p:commandLink value="Remove" update=":form:sharingUsers" process=":form:sharingUsers" action="#{sharingManagedBean.remove(user)}">  

                            </p:commandLink>  
                        </p:column>
                    </p:dataTable>
                </p:outputPanel>
                <f:facet name="footer">
                    <p:commandButton id="addButton" update="panelGrid" value="Add" action="#{sharingManagedBean.add()}"/>
                </f:facet>
            </p:panelGrid>
        </h:form>
    </ui:define>

</ui:composition>
